﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace UMS.Essences
{
    public class UIN
    {
        string val;

        public UIN()
        {
            val = Empty;
        }
        /// <summary>
        /// Парсит строку на предмет уина
        /// </summary>
        /// <param name="k">Строка из 10 цифр</param>
        /// <exception cref="ArgumentException">ArgumentException</exception>
        public UIN(string k)
        {
            Regex r = new Regex("^d{10}$");
            if (r.Match(k).Success)
                val = k;
            else
                throw new ArgumentException("Wrong UIN!");
        }

        public override string ToString()
        {
            return val;
        }
        
        public static string Empty = "0000000000";
        public static UIN NewUIN()
        {
            StringBuilder bld = new StringBuilder(0, 10);
            Random r = new Random(DateTime.Now.Millisecond);
            for (int i = 0; i < 5; i++)
            {
                Int32 k = Convert.ToInt32(r.NextDouble() * 100);
                bld.Append(k.ToString("D2"));
            }
            return new UIN(bld.ToString());
        }
    }
}
